import { Module } from 'vuex'
import { InitState } from '../types'
import { accountLoginRequest, accountUserInfoRequest } from '../../service/login/login';
import Localcache from '../../utils/cache'
import { IAccount } from '../../service/login/type';
import { ILoginState } from './types'
export const LoginModule: Module<ILoginState, InitState> = {
  namespaced: true,
  state() {
    return {
      token: '',
      UserInfo: {}
    }
  },
  mutations: {
    changeToken (state, token) {
      state.token  = token
    }
  },
  actions: {
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
     async  actionLogin({ commit }, payload: IAccount) {
      console.log('登录的actyiosn', payload);
      const resultRes = await accountLoginRequest(payload)
      // const { id, token } = resultRes.data.data
      console.log("resultRes", resultRes)
      // commit('changeToken', token)
      // Localcache.setCache('token', token)
      // const userRes  = await accountUserInfoRequest(id)
      // console.log("userResRes", userRes)
    },
    phoneLoginAction({ commit }, payload) {
      console.log("实现phoneLoginAction的逻辑", payload)
    }
  },
  getters: {}
}